package com.sqstudio.common
{
	import MyComponent.MyScrollPanel;
	
	import com.sqstudio.ui.ListItem;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;

	/**
	 *List命令器 
	 * @author Nestor
	 * 
	 */	
	public class ListCommander extends Sprite
	{
		private var _dateArr:Array;
		private var _labelArr:Array;
		private var _callBackFun:Function;
		private var _list:MyScrollPanel;
		public function ListCommander($labelArr:Array,$dataArr:Array,$callBack:Function,$pWH:Point)
		{
			this._labelArr = $labelArr;
			this._dateArr = $dataArr;
			this._callBackFun  = $callBack;
			
			this._list = new MyScrollPanel();
			addChild(this._list);
			this._list.setSize($pWH.x,$pWH.y);
			for(var i:int=0;i<this._dateArr.length;i++){
				var listItem:ListItem = new ListItem();
				listItem.name_txt.mouseEnabled = false;
				listItem.name_txt.text = String(this._labelArr[i]);
				listItem.addEventListener(MouseEvent.CLICK,itemCkHandler);
				listItem.name = String(this._dateArr[i]);
				listItem.y = i * (listItem.height);
				this._list.container.addChild(listItem);
			}
			this._list.containerChanged();
		}
		
		private function itemCkHandler(e:MouseEvent):void
		{
			var listItem:ListItem = e.currentTarget as ListItem;
			if(this._callBackFun != null){
				this._callBackFun(listItem.name);
			}		
		}
	}
}